DAY39:Smallest possible sum


Posted by birdbirdmurmur on 2023-08-21

題目連結

https://www.codewars.com/kata/52f677797c461daaf7000740

解法

function solution(X) {

    function gcd(a, b) {
        if (b === 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    const n = X.length;
    let result = X[0];

    for (let i = 1; i < n; i++) {
        result = gcd(result, X[i]);
    }

    return result * n;
}

筆記


#javascript #Codewars #gcd







Related Posts

V-for 的使用

V-for 的使用

 Week1 筆記|[GIT101]  GIT 學習筆記

Week1 筆記|[GIT101] GIT 學習筆記

超過 200 美金的教訓…三週托福 96→104 血淚經驗談(無補習、口說寫作未用模板)

超過 200 美金的教訓…三週托福 96→104 血淚經驗談(無補習、口說寫作未用模板)


Comments